package com.cat.dataStructure;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
*   @description https://leetcode.cn/problems/sort-vowels-in-a-string/?envType=daily-question&envId=2025-09-11
*   @author 曲大人的喵
*   @create 2025/9/11 14:35
*   @since JDK17
*/

public class Solution68 {
    public static boolean isVowel(char c) {
        c = Character.toLowerCase(c); // 转为小写统一判断
        return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
    }
    public String sortVowels(String s) {
        List<Character> list = new ArrayList<>();
        StringBuilder ans = new StringBuilder(s);
        for (int i = 0; i < s.length(); i++) {
            if (isVowel(s.charAt(i))) {
                list.add(s.charAt(i));
            }
        }
        Collections.sort(list);
        for (int i = 0, j = 0; i < ans.length(); i++) {
            if (isVowel(ans.charAt(i))) {   // 如果是元音
                ans.setCharAt(i, list.get(j++));
            }
        }

        return ans.toString();
    }
}
